package com.ykq.controller;

import com.ykq.entity.Menu;
import com.ykq.entity.Staff;
import com.ykq.service.MenuService;
import com.ykq.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @program: keyboard
 * @description:
 * @author: 闫克起2
 * @create: 2023-07-21 15:14
 **/
@RestController
@RequestMapping("/menu")
public class MenuController {
    @Autowired
    private MenuService menuService;

    @GetMapping("leftMenu")
    public Result leftMenu(HttpSession session) {
        //从session容器中获取当前用户信息
        Staff staff = (Staff) session.getAttribute("staff");
        List<Menu> list = menuService.findByRoleId(staff.getRoleid());
        return new Result(200, "查询左侧菜单成功", list);
    }

    @GetMapping("list")
    public Result list(Integer roleid) {
        List<Menu> list = menuService.findAll();
        List<Integer> list02 = menuService.findByRoleId02(roleid);
        Map<String,Object> map=new HashMap<String,Object>();
        map.put("list",list);
        map.put("list02",list02);
        return new Result(200, "查询所有菜单", map);
    }

    //确认分配菜单
    @PostMapping("fenQx")
    public Result fenQx(Integer roleId,Integer[] ids){
        menuService.fenQx(roleId,ids);
        return new Result(200,"分配菜单成功",null);
    }

}



















